<template>
	<view class="list">
		<view class="item" v-for="item in dataList">
			<view class="name">
				{{item.name}}
			</view>
			<view class="time">
				有效期至：{{item.outtime | formatDate}}
			</view>
			<view class="btn" @click="goDetail(item)">
				去使用
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabIndex: 0,
				dataList: [],
				shopId:"",
			}
		},
		components: {

		},
		onLoad(options) {
			// this.getLClassList();
			this.shopId = options.shopId;
		},
		onShow() {
			this.getList(); 
		},
		onShareAppMessage() {},
		filters: {
			formatDate: function(value) {
				var date = new Date();
				//date.setTime(value);
				var month = date.getMonth() + 1;
				var hours = date.getHours();
				if (hours < 10)
					hours = "0" + hours;
				var minutes = date.getMinutes();
				if (minutes < 10)
					minutes = "0" + minutes;
				var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
					" " + hours + ":" + minutes;
				return time;
			}

		},
		methods: {
			goMap(item) {
				uni.openLocation({
					longitude: Number(item.lng),
					latitude: Number(item.lat),
					name: item.address
				})
			},
			toPriceShow() {
				uni.navigateTo({
					url: './priceShow'
				})
			},
			getNearList() {
				this.$get('index/storelist', {
					page: 1,
					pagesize: 3,
					lng: this.longitude,
					lat: this.latitude,
				}, (res) => {
					this.nearList = res.list
				})
			},
			toInfo() {
				uni.navigateTo({
					url: '/pages/index/info'
				})
			},
			noPage() {
				uni.showToast({
					title: "功能开发中！",
					icon: "none"
				})
			},
			getList() {
				this.$get('coupon/couponlist', {
					page: 1,
					pagesize: 1000,
				}, (res) => {
					this.dataList = res
				})
			},
			goShopList(item) {
				uni.navigateTo({
					url: "/pages/shop/list_01?couponId=" + item.id
				})
			},
			goDetail(item) {
				console.log(item)
				if(this.shopId){
					uni.navigateTo({
						url: `/pages/shop/detail?shopId=${this.shopId}&couponId=${item.id}`
					})
				}else{
					this.goShopList(item)
				}
			},
		}
	}
</script>

<style>
	page {
		background: #F5F5F5;
	}

	.item {
		width: 700rpx;
		border-radius: 16rpx;
		background: url(../../static/index_bg.png);
		background-size: 100% 100%;
		margin: 20rpx 24rpx 0;
		padding: 36rpx;
		position: relative;
	}

	.item .name {
		color: #333333;
		font-size: 34rpx;
		height: 90rpx;
		line-height: 45rpx;
		overflow: hidden;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		display: -webkit-box;
		width: 410rpx;
	}

	.item .time {
		color: #999999;
		font-size: 24rpx;
		margin-top: 16rpx;
		width: 410rpx;
	}

	.item .btn {
		position: absolute;
		top: 78rpx;
		right: 32rpx;
		width: 148rpx;
		height: 54rpx;
		line-height: 54rpx;
		text-align: center;
		color: #FFFFFF;
		background-color: #FE0520;
		border-radius: 30px;
	}
</style>
